package com.noble.glamour.module.local.chat.utils;

import android.text.TextUtils;

import com.noble.glamour.R;
import com.noble.glamour.module.local.chat.msgtype.bean.BaseMessage;
import com.noble.glamour.module.local.chat.msgtype.BaseMessageType;
import com.noble.glamour.module.local.chat.msgtype.type.CommonMessage;
import com.noble.glamour.module.local.chat.msgtype.type.InviteVideoMessage;
import com.noble.glamour.module.local.chat.msgtype.type.VideoMessage;
import com.noble.glamour.module.logic.application.App;
import com.noble.glamour.module.util.TimeUtil;
import com.noble.mail.MessageConstant;

/**
 * 消息中，各种拼接字符串工具类
 */
public class MsgStringUtils {

    /**
     * 列表显示转换
     */
    public static String getContent(BaseMessage msg) {
        String result = "";
        BaseMessageType messageType = BaseMessageType.valueOf(msg.getType());
        if (messageType == null) {
            return result;
        }
        switch (messageType) {
            case hi:
                String content = msg.getMsgDesc();
                if (TextUtils.isEmpty(content)) {
                    result = "[打招呼]";
                } else {
                    result = content.replaceAll("Glamour", App.context.getString(R.string.app_name));
                }
                break;
            case common:
                result = msg.getMsgDesc();
                if (TextUtils.isEmpty(result)) {
                    CommonMessage commonMessage = (CommonMessage) msg;

                    String videoUrl = commonMessage.getVideoUrl();
                    String localVideoUrl = commonMessage.getLocalVideoUrl();
                    String voiceUrl = commonMessage.getVoiceUrl();
                    String localVoiceUrl = commonMessage.getLocalVoiceUrl();
                    String img = commonMessage.getImg();
                    String localImg = commonMessage.getLocalImg();
                    if (!TextUtils.isEmpty(videoUrl) || !TextUtils.isEmpty(localVideoUrl)) {//视频
                        result = "[视频]";
                    } else if (!TextUtils.isEmpty(voiceUrl) || !TextUtils.isEmpty(localVoiceUrl)) {//语音
                        result = "[语音]";
                    } else if (!TextUtils.isEmpty(img) || !TextUtils.isEmpty(localImg)) {//图片
                        result = "[图片]";
                    }
                }
                break;
            case video: {
                VideoMessage videoMessage = (VideoMessage) msg;
                boolean sender = videoMessage.getStatus() == MessageConstant.OK_STATUS ||
                        videoMessage.getStatus() == MessageConstant.FAIL_STATUS || videoMessage.getStatus() == MessageConstant.SENDING_STATUS;
                result = VideoMessage.transLastStatusText(videoMessage.getEmLastStatus(),
                        TimeUtil.getFormatTimeChatTip(TimeUtil.onPad(videoMessage.getTime())), sender);
                break;
            }
            case hint:
            case html://html消息
            case htmlText:
                result = msg.getMsgDesc();
                break;
            case gift:
            case wantGift:
                result = "[礼物]";
                break;
            case autoUpdateHtml:
                result = "[系统消息]";
                break;
            case sysNotice:
                result = "[系统通知]";
                break;
            case inviteVideoMass:
                InviteVideoMessage inviteMessage = (InviteVideoMessage) msg;
                if (inviteMessage.getMedia_tp() == 1) {
                    result = "[视频邀请]";
                } else {
                    result = "[语音邀请]";
                }
                break;
            case maxVersion:
                result = "[你的版本过低，无法接收此类消息]";
                break;
            default:
                result = msg.getMsgDesc();
                break;
        }
        return result;
    }
}
